package cfdt.ldl.web.config;

import cfdt.ldl.web.interceptor.BaseInterceptor;
import cfdt.ldl.web.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private BaseInterceptor baseInterceptor;
    @Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加基础拦截器
        registry.addInterceptor(baseInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**")
                // 放行不需要拦截的路径
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/v3/api-docs/**")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/favicon.ico");

        // 添加Token拦截器
        registry.addInterceptor(tokenInterceptor)
                // 拦截所有请求
                .addPathPatterns("/**")
                // 放行不需要拦截的路径
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/v3/api-docs/**")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/favicon.ico")
                .excludePathPatterns("/user/login/**");
    }

}
